"""
对话框例子的UI层
"""
import typing

from elio import core


class DialogLayer(core.AutoRecycleLayer[core.Activity]):
    btnShow: core.WidgetButton

    async def on_create(self, *args: typing.Any, **kwargs: typing.Dict):
        await super().on_create(*args, *kwargs)

    async def on_hide(self):
        await super().on_hide()
        await self.btnShow.destroy()

    async def on_show(self):
        await super().on_show()
        activity = self.parent
        # 点击弹出对话框的按钮
        self.btnShow = await core.WidgetButton.create(activity, 400, 40, 200, 200, '测试对话框')
        await self.btnShow.set_on_click_listener(self.show_dialog)

    async def show_dialog(self):
        """
        显示对话框。
        """
        dialog = await core.GenericDialog.create(self.parent, '提示', '这是对话框内容', '确定')

        async def cb_ok():
            """
            确定按钮点击事件。
            """
            print('点击确定按钮')
            await dialog.destroy()

        await dialog.set_on_ok_button_click_listener(cb_ok)

        async def cb_cancel():
            """
            取消按钮点击事件。
            """
            print('对话框取消')
            await dialog.destroy()

        await dialog.set_on_cancel_listener(cb_cancel)

    async def on_pause(self):
        await super().on_pause()

    async def on_resume(self):
        await super().on_resume()

    async def on_destroy(self, *args: typing.Any, **kwargs: typing.Dict):
        await super().on_destroy(*args, **kwargs)
